package com.dycx.api.controller.manage.system;

import com.dycx.common.annotation.WriterLog;
import com.dycx.common.RestResponse;
import com.dycx.common.enums.BizTypeEnum;
import com.dycx.system.dto.RoleDTO;
import com.dycx.system.service.RoleService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping(value = "/manage/system/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    /**
     * 添加
     **/
    @WriterLog(bizType = BizTypeEnum.SYS_ROLE, bizValue = "{#roleDto.id}")
    @PostMapping("/insert")
    public RestResponse<?> insert(@RequestBody @Valid RoleDTO roleDto) {
        return roleService.insert(roleDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 修改
     **/
    @WriterLog(bizType = BizTypeEnum.SYS_ROLE, bizValue = "{#roleDto.id}")
    @PostMapping("/update")
    public RestResponse<?> update(@RequestBody @Valid RoleDTO roleDto) {
        return roleService.update(roleDto) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 刪除
     **/
    @WriterLog(bizType = BizTypeEnum.SYS_ROLE, bizValue = "{#roleId}")
    @GetMapping("/delete")
    public RestResponse<?> delete(int roleId) {
        return roleService.delete(roleId) ? RestResponse.success() : RestResponse.fail();
    }

    /**
     * 查询 根据主键 id 查询
     **/
    @GetMapping("/getAllList")
    public RestResponse<?> getAllList() {
        return RestResponse.success(roleService.getAllList(0));
    }

}
